#include "LinkSerialClient.h"
#include "PacketHexBase.h"
#include <iostream>
#include "lib.h"
#include "IMode.h"

using namespace controller;

void test_IMode(void)
{
    PacketHexBase packet_hex;
    LinkSerialPort l;
    std::map<std::string, std::string> arg = {
        {"dev", "/dev/ttyv0"},
        //{"dev","/dev/ttyS0"},
        {"baud", "115200"}};
    l.set_dump_buffer_type(true);
    l.open(arg);
    packet_hex.build(1, 2, 12345678, 1, 0x3101, 5, (uint8_t *)"12345");

    // // 1. 测试 发送-
    // IMode::S2(&l, [&](LinkBase *l)
    //           { return new PacketHexBase(); }, (PacketBase *)&packet_hex, [&](LinkBase *l, PacketBase *r)
    //           { std::cout << "我用函数发送，我真的接收到了一个数据包啦" << std::endl; }, 5000);

    IMode::S2(&l, (PacketBase *)&packet_hex, (PacketBase *)&packet_hex, [&](LinkBase *l, PacketBase *r)
              { std::cout << "我用对象发送，我真的接收到了一个数据包啦" << std::endl; }, 5000);

    // 组包

    // IMode::W(&l, &packet_hex, [&](LinkBase *l, PacketBase *p)
    //          {
    //     static int c = 0;
    //     std::cout << "第 " << std::to_string(c) << " 数据包"  << std::endl;
    //     c++; }, 10000);

    l.close();
}